using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using THSLib;
using THSERP.BaseProvider;

namespace THSERP.Modules.ProcessFood
{
    public class ICProcessFoodItemsGridControl : THSGridControl
    {
        private DevExpress.XtraGrid.Views.Grid.GridView gridView1;
    
        protected override DevExpress.XtraGrid.Views.Grid.GridView InitializeGridView()
        {
            DevExpress.XtraGrid.Views.Grid.GridView gridView = base.InitializeGridView();

            //Check edit item privilege_Hieu.nguyen_29/04/2010
            ProcessFoodEntities entity = (ProcessFoodEntities)(this.Screen.Module as BaseModuleERP).CurrentModuleEntity;
            if (entity.Module.HasPrivilege("EditItem"))
            {
                if (gridView.Columns["ICProcessFoodItemProductQty"] != null)
                    gridView.Columns["ICProcessFoodItemProductQty"].OptionsColumn.AllowEdit = true;
                if (gridView.Columns["ICProcessFoodItemProductUnitCost"] != null)
                    gridView.Columns["ICProcessFoodItemProductUnitCost"].OptionsColumn.AllowEdit = true;
            }

            return gridView;
        }

        protected override void GridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            base.GridView_CellValueChanged(sender, e);

            ProcessFoodEntities entity = (ProcessFoodEntities)(this.Screen.Module as BaseModuleERP).CurrentModuleEntity;
            if (entity.ICProcessFoodItemsList.CurrentIndex >= 0)
            {
                entity.ModuleObjects[ProcessFoodEntities.strICProcessFoodItemsObjectName] = entity.ICProcessFoodItemsList[entity.ICProcessFoodItemsList.CurrentIndex].SetToBusinessObject(ProcessFoodEntities.strICProcessFoodItemsObjectName);
                (entity.Module as ProcessFoodModule).ChangeItemFromProcessFoodItemsList();
            }
        }

        public override void InitGridControlDataSource()
        {
            //base.InitGridControlDataSource();
            ProcessFoodEntities entity = (ProcessFoodEntities)((BaseModuleERP)Screen.Module).CurrentModuleEntity;
            BindingSource bds = new BindingSource();
            bds.DataSource = entity.ICProcessFoodItemsList;
            this.DataSource = bds;
        }

        protected override string GetLookupTableDisplayColumn(string strLookupTableName)
        {
            switch (strLookupTableName)
            {
                case "ICProducts":
                    return "ICProductNo";
                default:
                    return base.GetLookupTableDisplayColumn(strLookupTableName);
            }
        }

        private void InitializeComponent()
        {
            this.gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView();
            ((System.ComponentModel.ISupportInitialize)(this.gridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            // 
            // gridView1
            // 
            this.gridView1.GridControl = this;
            this.gridView1.Name = "gridView1";
            // 
            // ICProcessFoodItemsGridControl
            // 
            this.MainView = this.gridView1;
            this.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
            this.gridView1});
            ((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);

        }
    }
}
